package com.fangcang;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;

import com.alibaba.fastjson.JSONObject;
import com.fangcang.mongodb.config.MongoConfig;
import com.fangcang.mongodb.impl.MongoBuilder;
import com.fangcang.mongodb.impl.MongoDbApiService;
import com.fangcang.mongodb.model.PageResult;
import com.fangcang.rest.city.Province;
import com.fangcang.service.MerchantService;
import com.mongodb.client.model.Filters;

@SpringBootApplication
@ServletComponentScan("com.fangcang.filter")
@MapperScan("com.fangcang.dao")
public class SpringBootDemoApplication {

	public static void main(String[] args) throws Exception {
		ApplicationContext ac = SpringApplication.run(SpringBootDemoApplication.class, args);
		
//		DemoService service = (DemoService)ac.getBean("demoService");
//		System.out.println(JSONObject.toJSON(service.getData()));
		
//		RedisService service = (RedisService)ac.getBean("redisService");
//		service.getRedis();
//		service.setBigDataToRedis();
		
		
//		BaiDuApiUtils service = (BaiDuApiUtils)ac.getBean("baiDuApiU

//		ThreadPoolService service = (ThreadPoolService)ac.getBean("threadPoolService");
//		service.execute("07:qunar:");
		
	/*	MongoDbApiService service = ac.getBean("mongoDbApiService", MongoDbApiService.class);
		UserBean user = new UserBean();
		user.setUserId(new Random(100000).nextLong() + "");
		user.setUserName(UUID.fromString("test").toString());
		service.insertOne(user);*/
		
		//builderMongo();
		MerchantService service = (MerchantService)ac.getBean("merchantService");
		service.initMerchantCity();
	}

	
	@SuppressWarnings("unused")
	private static void builderMongo() {
		MongoConfig mongoConfig = new MongoConfig("192.168.2.202", 27017, "knight", "hcq514", "123456", "city_list");
		MongoDbApiService service = new MongoDbApiService(mongoConfig);
		
		PageResult<Province> page = new PageResult<Province>(1, 10);
		page = service.findManyByPage(MongoBuilder.builder().elmeMatch("citys", Filters.eq("cityCode", "GC")).getFilters(), Province.class, page);
		page.getList().forEach(userBean ->{
			System.out.println(JSONObject.toJSONString(userBean));
		});
		System.out.println("总记录条数：" + page.getTotal());
	}
}
